<div class="layui-fluid layui-anim febs-anim" id="febs-dict" lay-title="活动数据字典">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="dictDetail-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">字典名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="shellActivityDic:add,shellActivityDic:update,shellActivityDic:export">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="dictTable" lay-data="{id: 'dictTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="dict-option">
    <span shiro:lacksPermission="shellActivityDic:view,shellActivityDic:update,shellActivityDic:delete,shellActivityDic:dictDetail">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <span shiro:hasPermission="shellActivityDic:update"><button lay-event="update" type="button" class="layui-btn layui-btn-xs">修改</button></span>
    <span shiro:hasPermission="shellActivityDic:delete"><button lay-event="delete" type="button" class="layui-btn layui-btn-xs">删除</button></span>
    <span shiro:hasPermission="shellActivityDic:dictDetail"><button lay-event="info" type="button" class="layui-btn layui-btn-xs">明细</button></span>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#febs-dict'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            tableIns,
            singleDictObj,
            element = layui.element;

        form.render();

        initTable();

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('dictTable');
                if (name === 'add') {
                    febs.modal.open('新增活动字典', 'activity/shellActivityDic/add/' + 0, {
                        area: $(window).width() <= 750 ? '90%' : '50%'
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的活动数据字典');
                    } else {
                        febs.modal.confirm('删除活动数据字典', '确定删除活动数据字典？', function () {
                            var Ids = [];
                            layui.each(checkStatus.data, function (key, item) {
                                Ids.push(item.id)
                            });
                            deleteOilPrice(Ids.join(','));
                        });
                    }
                }
            },
            options: [{
                name: 'add',
                title: '新增字典',
                perms: 'shellActivityDic:add'
            }, {
                name: 'delete',
                title: '删除字典',
                perms: 'shellActivityDic:delete'
            }, {
                name: 'export',
                title: '导出Excel',
                perms: 'shellActivityDic:export'
            }]
        });

        table.on('tool(dictTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            var dataString = JSON.stringify(data);
            if (layEvent === 'update') {
                localStorage.setItem('dictVal', dataString);
                febs.modal.open('修改活动字典', 'activity/shellActivityDic/add/' + 1, {
                    area: $(window).width() <= 750 ? '90%' : '50%'
                });
            }
            if (layEvent === 'delete') {
                febs.modal.confirm('删除活动数据字典', '确定删除该活动数据字典？', function () {
                    deleteOilPrice(data.id);
                });
            }
            if (layEvent === 'info') {
                febs.view.tab.change("/activity/shellActivityDic/dictDetail/" + data.id);
            }
        });
        table.on('sort(dictTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            tableIns.reload({where: getQueryParams(), page: {curr: 1}});
        });
        //列表数据-请求
        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'dictTable',
                url: ctx + 'shellActivity/dictList',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'name', title: '字典名称', minWidth: 100},
                    {field: 'code', title: '字典编码', minWidth: 100},
                    {field: 'remark', title: '备注', minWidth: 100},
                    {title: '操作', toolbar: '#dict-option', minWidth: 140}
                ]]
            });
        }
        //数据详情-请求
        function initDataInfo(id) {

        }

        function getQueryParams() {
            return {
                name: $searchForm.find('input[name="name"]').val()
            };
        }

        function deleteOilPrice(dsIds) {
            // console.log(dsIds)
            febs.get(ctx + 'shellActivity/dicDelete/' + dsIds , null, function () {
                febs.alert.success('删除活动数据字典成功');
                $query.click();
            });
        }

    })
</script>